package org.example.linkedList;

import java.util.Arrays;

/**
 * @Auther: wangbw
 * @Date:2020/12/9
 * @Description: org.example.linkedList
 * @version: 1.0
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] arr = new int[] { 4, 5, 3, 2, 8 };
        sort(arr);
        print(arr);
    }

    private static void print(int[] arr) {
        System.out.println("result:" + Arrays.toString(arr));
    }

    private static void sort(int[] arr) {
        if (arr == null || arr.length <= 1)
            return;
        Boolean flag = false;
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++)
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j + 1];
                    arr[j + 1] = arr[j];
                    arr[j] = temp;
                    flag = true;
                }
            System.out.println(Arrays.toString(arr));
            if (!flag)
                return;
        }
    }
}

    
